function [ association, LA, S, associationUser_final ] = cell_association( Degree, Candidate, SINRinfo, SINRinfo_db )
global userNum LL_max BSnum PP_w Load_max PP_w_c userinfo;

LA=zeros(size(LL_max));
S=ones(1,userNum);
associationUser=zeros(1,userNum);
association=zeros(BSnum,100);

   while ~(isempty(find(associationUser==0)))
          unAssociated=find(associationUser==0);
          [v,x]=min(Degree(unAssociated));
          j=unAssociated(x);
          Can=setdiff(Candidate(j,:),0);
          SINR=SINRinfo(j,Can);
          Lcan_max=LL_max(Can);
          Load_maxt=Load_max(Can);
          La=LA(Can);
          Lc=Load_maxt-La;
          p=zeros(1,size(Can,2));
         
    for ii=1:size(Can,2)
        if La(ii)+1<=Lcan_max(ii)
            p(ii)=1;
           
        else
%             if Lcan_max(ii)<La(ii)+1<=Load_maxt(ii)
               p(ii)=Lcan_max(ii)/(La(ii)+1);
%             else
%                 p(ii)=0;
%             end
        end
    end
    
    
    
     W=(Lc./Load_maxt).*p;

    Rate=0.6*log2(1+SINR)*180e3;
%     EE_max=4.4*180e3./PP_w(Can)
    EE=Rate./PP_w_c(Can);
    EE_w=W.*EE;
    [val,index]=max(EE_w);
    cell=Can(index);
    LA(cell)=LA(cell)+1;    
    association(cell,LA(cell))=j;
    associationUser(1,j)=cell;
    S(j)=SINRinfo_db(j,cell);
  %%  
    unassociated=find(associationUser==0);
    total=size(find(associationUser==0),2);
    for t=1:total
        jj=unassociated(t);
        index=find(SINRinfo_db(jj,:)>userinfo(jj,3));
        index1=find(LA<Load_max);
        can=intersect(index,index1);
        if isempty(can)     
           associationUser(1,jj)=BSnum+1;
           Candidate(jj,:)=0;
        else
           Degree(jj)=size(can,2);
           Candidate(jj,:)=0;
           Candidate(jj,1:Degree(jj))=can;
       end
    end
%     [ Degree, Candidate, associationUser ] = update_degree_candidate( SINRinfo_db, LA, associationUser,Degree, Candidate );
   
        
  end
associationUser_final=associationUser;
end
